package cn.tedu.hotel.serve.service.impl;

import cn.tedu.hotel.serve.mapper.SecondaryBannerMapper;
import cn.tedu.hotel.serve.pojo.entity.secondary.Banner;
import cn.tedu.hotel.serve.service.ISecondaryBannerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Slf4j
@Service
public class SecondaryBannerServiceImpl implements ISecondaryBannerService {
    @Value("${dirPath}")
    private String dirPath;
    @Autowired
    SecondaryBannerMapper secondaryBannerMapper;

    @Override
    public List<Banner> select() {
        List<Banner> list =secondaryBannerMapper.select();
        log.debug("查询轮播图列表完成");
        return list;
    }

    @Override
    public void deleteById(Long id) {
        Banner banner = secondaryBannerMapper.selectById(id);
        System.out.println("id="+id);
/*        new File(dirPath+banner.getUrl()).delete();
        log.debug("本地轮播图已删除");*/
        secondaryBannerMapper.deleteById(id);
        log.debug("数据库轮播图已删除");
    }

    @Override
    public void insert(String url) {
        log.debug("开始处理【添加轮播图】的业务");
        secondaryBannerMapper.insertBanner(url);
        log.debug("添加完成");
    }

    @Override
    public Banner selectById(Long id) {
        Banner queryResult = secondaryBannerMapper.selectById(id);
        log.debug("按照ID查询轮播图完成");
        return queryResult;
    }

    @Override
    public void update(Banner banner) {
        secondaryBannerMapper.update(banner);
        log.debug("更新轮播图完成");
    }
}
